package com.ganee.agora.viewmodel

import android.app.Application
import androidx.lifecycle.MutableLiveData
import com.alibaba.android.arouter.launcher.ARouter
import com.ganee.agora.event.PostEvent
import com.ganee.agora.model.FileEntity
import com.ganee.agora.repository.PostEventRepository
import com.ganee.baselib.arouter.Constance
import com.ganee.baselib.httprequest.callback.RequestCallback
import com.ganee.baselib.httprequest.callback.RequestMultiplyCallback
import com.ganee.baselib.httprequest.exception.ApiException
import com.ganee.baselib.mvvmlibrary.base.BaseViewModel
import okhttp3.RequestBody
import org.greenrobot.eventbus.EventBus

class PostEventViewModel(application: Application) : BaseViewModel<PostEventRepository>(application) {

    var uploadFile = MutableLiveData<FileEntity>()

    override fun getRepository(): PostEventRepository {
        return PostEventRepository(this)
    }


    //发布活动
    fun postEvent(body: RequestBody) {
        mRepository.postEvent(body, RequestCallback {
            ARouter.getInstance()
                    .build(Constance.ACTIVITY_URL_POST_SUCCESSFULLY)
                    .withString("host",it.host)
                    .navigation()
        })
    }

    fun uploadFile(body: RequestBody,callback: RequestMultiplyCallback<FileEntity>) {
        mRepository.uploadFile(body,callback)
    }
}
